import java.net.Socket;

/**
 * 一个连接服务端的工具类
 * @author 乐心湖
 * @version 1.0
 * @date 2021/9/8 8:52
 */
public class ConnectedUtils {
    public static Socket getConnection() throws InterruptedException {
        //ConnectedUtils connectedUtils = new ConnectedUtils();
        Socket socket = null;
        while (socket == null) {
            try {
                System.out.println("正在连接服务器");
                socket = new Socket("localhost", 9900);
            } catch (Exception e) {
                socket = null;
                //连接不上，5秒重连
                Thread.sleep(5000);
                MyClientSocket.setOisUpdated(true);
                MyClientSocket.setOosUpdated(true);
            }
        }
        return socket;
    }
}
